home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: Bradd W. Szonye <bradds@ix.netcom.com>
- Newsgroups: comp.lang.c++
- Subject: RE: Small question
- Date: 19 Apr 1996 09:49:47 GMT
- Organization: Netcom
- Message-ID: <01bb2dd5.d605aa00$c6c2b7c7@Zany.localhost>
- References: <4k822h$s8t@pub.news.uk.psi.net>
- NNTP-Posting-Host: det-mi6-06.ix.netcom.com
- X-NETCOM-Date: Fri Apr 19 4:49:47 AM CDT 1996
- X-Newsreader: Microsoft Internet News
-
-
- On Sunday, April 07, 1996, andrew oxenburgh wrote...
- > sence@ava.taby.se (Bjorn Osterman) writes:
- > > If I have 2 cpp files and i use the same global variable that i define
- > > in some file that both cpp-files includes. How do I tell the compiler
- > > that the variable is the same and that it shouldn't make space 2
- > > times?
- > >
- > >
- > >
- > > // bjorn@ava.taby.se
- > > // http://www.ava.taby.se/www/sence
- >
- >
- > Bjorn,
- >
- > Put the global once in a common header????
- >
- > chz
- >
- > andrewo
- >
- Not exactly.
-
- For, say, a global integer called "foo":
-
- source file 1:
- extern int foo;
- int foo = 1;
-
- source file 2:
- extern int foo;
-
- The "extern" declarations can go in a header, or right in your source
- files.
- But make sure you define it only once (the = 1 line), especially in C++,
- which is less forgiving about such things than C is.
-
-
-